package com.liqin.nothing.config.sensitiveword;

import com.github.houbb.sensitive.word.api.IWordAllow;
import com.github.houbb.sensitive.word.api.IWordDeny;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.github.houbb.sensitive.word.support.allow.WordAllows;
import com.github.houbb.sensitive.word.support.deny.WordDenys;
import com.github.houbb.sensitive.word.support.resultcondition.WordResultConditions;
import com.github.houbb.sensitive.word.support.tag.WordTags;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 敏感词配置类，用于设置敏感词过滤器的自定义过滤策略
 * 更多配置见 <a href="https://github.com/houbb/sensitive-word">此处</a>
 *
 * @author gonghl
 */
@Configuration
public class SensitiveWordConfig {
    @Bean
    public SensitiveWordBs sensitiveWordBs() {

        // 合并默认和自定义敏感词
        IWordDeny wordDeny = WordDenys.chains(WordDenys.defaults(), new MyWordDeny());
        // 合并默认和自定义允许词
        IWordAllow wordAllow = WordAllows.chains(WordAllows.defaults(), new MyWordAllow());

        return SensitiveWordBs.newInstance()
                .ignoreCase(true)           // 忽略大小写，默认值为true
                .ignoreWidth(true)          // 忽略半角圆角，默认值为true
                .ignoreNumStyle(true)       // 忽略数字的写法，默认值为true
                .ignoreChineseStyle(true)   // 忽略中文的书写格式，默认值为true
                .ignoreEnglishStyle(true)   // 忽略英文的书写格式，默认值为true
                .ignoreRepeat(false)        // 忽略重复词，默认值为false
                .enableNumCheck(false)      // 是否启用数字检测，默认值为false
                .enableEmailCheck(false)    // 是有启用邮箱检测，默认值为false
                .enableUrlCheck(false)      // 是否启用链接检测，默认值为false
                .enableIpv4Check(false)     // 是否启用IPv4检测，默认值为false
                .enableWordCheck(true)      // 是否启用敏感单词检测，默认值为true
                .numCheckLen(8)             // 数字检测，自定义指定长度，默认值为8
                .wordTag(WordTags.none())   // 词对应的标签，默认值为none
                .charIgnore(new MyIgnoreChar())                             // 忽略的字符，默认值为none
                .wordResultCondition(WordResultConditions.alwaysTrue())     // 针对匹配的敏感词额外加工，比如可以限制英文单词必须全匹配，默认恒为真
                .wordDeny(wordDeny)         // 敏感词
                .wordAllow(wordAllow)       // 允许词
                .init();
    }
}
